package com.wisezone.springmvc.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
/**
 *  1.拦截器实现HandlerInterceptor接口
 *
 */
public class MyInterceptor implements HandlerInterceptor {
	/**
	 * Controller方法执行之前调用
	 */
	@Override
	public boolean preHandle(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2) throws Exception {
		System.out.println("preHandle >>>>");
		return true;  //如果返回true请求继续执行，返回false请求终止
	}
	
	/**
	 * Controller方法执行之后视图View渲染之前调用
	 */
	@Override
	public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, ModelAndView arg3)
			throws Exception {
		System.out.println("postHandle >>>>");
	}
	
	/**
	 * 视图View渲染之后调用
	 */
	@Override
	public void afterCompletion(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, Exception arg3)
			throws Exception {
		System.out.println("afterCompletion >>>>");
	}
}
